Skip to content

perf(markdown): cache completed streaming blocks#7306

Merged
c121914yu merged 1 commit into
labring:mainfrom
c121914yu:codex/chatbox-stream-cache
Jul 14, 2026
Merged

perf(markdown): cache completed streaming blocks#7306
c121914yu merged 1 commit into
labring:mainfrom
c121914yu:codex/chatbox-stream-cache

Conversation

@c121914yu

Copy link
Copy Markdown
Collaborator

Summary

  • split streaming Markdown into root-level blocks and memoize completed blocks
  • keep the existing tail-only fade on the active block
  • preserve cross-block reference links and GFM footnotes by falling back to full-document rendering

Verification

  • pnpm exec vitest run -c vitest.config.ts test/components/Markdown/streamMarkdownBlocks.test.ts test/components/Markdown/rehypeStreamAnimated.test.ts test/components/Markdown/utils.test.ts --run --coverage=false
  • app test suite: 150 test files passed; the 8 initial sandbox-adapter resolution failures passed after building the local workspace package
  • targeted ESLint and Prettier checks passed

No documentation changes.

@github-actions

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 18.43% 1632 / 8855
🔵 Statements 18.41% 1713 / 9300
🔵 Functions 16.21% 342 / 2109
🔵 Branches 15.1% 759 / 5024
File CoverageNo changed files found.
Generated in workflow #1407 for commit a584507 by the Vitest Coverage Report Action

@github-actions

Copy link
Copy Markdown

Admin Preview Image Ready!

ghcr.io/labring/fastgpt-pr:admin_a584507d9b4f14b76b2ac61385cb236253723de8

🕒 Time: 2026-07-14 21:12:06 (UTC+8)

@github-actions

Copy link
Copy Markdown

Build Successful - Preview fastgpt Image for this PR:

ghcr.io/labring/fastgpt-pr:fastgpt_a584507d9b4f14b76b2ac61385cb236253723de8

🕒 Time: 2026-07-14 21:14:28 (UTC+8)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves streaming Markdown rendering performance in the app by splitting streamed Markdown into root-level blocks and memoizing completed blocks so only the actively-growing block re-renders. It maintains the existing “tail-only” fade animation on the active block and preserves correctness for cross-block reference links / GFM footnotes by falling back to full-document rendering when those constructs are present.

Changes:

  • Add a splitMarkdownBlocks utility that parses Markdown and slices the source into stable root-level blocks (with a full-document fallback for references/footnotes).
  • Update the Markdown renderer to render blocks via a memoized MarkdownStreamBlock, applying the streaming tail animation only to the last block.
  • Add unit tests for block splitting behavior and rendering equivalence, and add required parser dependencies.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
projects/app/test/components/Markdown/streamMarkdownBlocks.test.ts Adds tests covering block splitting rules, offsets, and render equivalence across block rendering vs full-document rendering.
projects/app/src/components/Markdown/streamMarkdownBlocks.ts Implements Markdown root-level block splitting using unified + remark-parse with math/GFM support and fallbacks for references/footnotes/whitespace-only input.
projects/app/src/components/Markdown/index.tsx Refactors streaming rendering to memoize completed blocks and keep tail fade on the active (last) block.
projects/app/package.json Adds direct dependencies needed for parsing (remark-parse, unified).
pnpm-lock.yaml Updates lockfile for the newly added dependencies.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@c121914yu c121914yu merged commit f60c459 into labring:main Jul 14, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants